{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 20,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "(1, 2, 3, 412, '213')\n",
      "412\t\t\t213\n",
      "<class 'int'> <class 'str'>\n"
     ]
    }
   ],
   "source": [
    "# 字面量定义元组\n",
    "t = (1,2,3,412,'213')\n",
    "print(t)\n",
    "print (t[3],t[4],sep='\\t\\t\\t')\n",
    "print (type(t[3]),type(t[4]))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "('h', 'e', 'l', 'l', 'o')\n",
      "(1, 2, 3)\n"
     ]
    }
   ],
   "source": [
    "# 元组的构造方法定义元组\n",
    "t1 = tuple('hello')\n",
    "print(t1)\n",
    "t2 = tuple([1,2,3])\n",
    "print(t2)"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "wdas\n",
      "3435\n"
     ]
    }
   ],
   "source": [
    "# 元组中元素的引用\n",
    "t3 = (123,'23','add',(2,'wdas',1),[213,31234,3435])\n",
    "print(t3[3][1])\n",
    "print(t3[4][2])"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'dict_values'>\n"
     ]
    }
   ],
   "source": [
    "# 元组切片操作  同字符串一致\n",
    "print(type({'a1': 'aaa', 'a2': 'bbb'}.values()))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "2\n",
      "2\n"
     ]
    }
   ],
   "source": [
    "#元组常用方法  len()  count()  index()\n",
    "print(t1.count('l'))\n",
    "print(t1.index('l'))"
   ],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [],
   "metadata": {
    "collapsed": false,
    "pycharm": {
     "name": "#%%\n"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}